<?php
/**
* @package		JBS
* @license		GNU/GPL, see LICENSE.php
*/

jimport( 'joomla.application.component.view');

/**
 * HTML View class for the JBS Component
 *
 * @package		JBS
 */
class JBSViewAssets extends JView
{
	function display($tpl = null)
    {
        $task = JRequest :: getVar('task');
		switch ($task) {
			case 'showGroup':

				break;
			case 'edit':
			case 'add':
				//get all assetgroups from Request
		        $assetgroups = JRequest::getVar('assetgroups');

				$assets	= & $this->get('Data');
				$isNew = ($assets->id < 1);

				$text = $isNew ? JText::_( 'New' ) : JText::_( 'Edit' );
				JToolBarHelper :: title(JText::_('PROJECT NAME').' - '.JText::_( 'ASSETS' ).': <small><small>[ ' . $text.' ]</small></small>', 'jbschedule' );
				JToolBarHelper::save();
				if ($isNew)  {
					JToolBarHelper::cancel();
				} else {
					// for existing items the button is renamed `close`
					JToolBarHelper::cancel( 'cancel', 'Close' );
				}
				$this->assignRef('assets',		$assets);

				//Chuyen assetgroups cho Template
				$this->assignRef('assetgroups', $assetgroups);

				break;

			default:				
				global $mainframe, $option;
				//initialise variables
				//$document	= & JFactory::getDocument();
				$db			= & JFactory::getDBO();
				//$user 		= & JFactory::getUser();
				
				
				
				//get vars
				$filter_order		= $mainframe->getUserStateFromRequest( $option.'.assets.filter_order', 'filter_order', 	'name', 'cmd' );				
				$filter_order_Dir	= $mainframe->getUserStateFromRequest( $option.'.assets.filter_order_Dir', 'filter_order_Dir', '', 'word' );
				$search 			= $mainframe->getUserStateFromRequest( $option.'.assets.search', 'search', '', 'string' );
				$search 			= $db->getEscaped( trim(JString::strtolower( $search ) ) );
				$template			= $mainframe->getTemplate();
				
				JToolBarHelper::title(JText::_('PROJECT NAME').' - '.JText :: _( 'ASSETS MANAGER' ), 'jbschedule');
				JToolBarHelper::deleteList(JText :: _( 'ARE YOU SURE' ));//param: 1: message 2: task to do 3: Label of the button
				JToolBarHelper::editListX();
				JToolBarHelper::addNewX();
				
				
				// Get data from the model
				$items      = & $this->get( 'DataList');
				//$total    = & $this->get( 'Total');
				$pageNav 	= & $this->get( 'Pagination' );				
				
				// table ordering
				$lists['order_Dir'] = $filter_order_Dir;
				$lists['order'] = $filter_order;
		
				// search filter
				$lists['search']= $search;

				$this->assignRef('items'		, $items);				
				$this->assignRef('lists'      	, $lists);
				$this->assignRef('pageNav' 		, $pageNav);
				$this->assignRef('template'		, $template);
				break;
		}

		parent :: display($tpl);
    }

}
?>
